package com.nwork.cateye.adapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import java.util.List;

/**
 * Created by licheng
 * date:2015/2/4
 * email:635408136@qq.com
 */

/**
 * 通用的显示Adapter
 */
public class CommenImagePageAdapter extends PagerAdapter {
    private List<Integer> imgeIds;
    private Context context;

    public CommenImagePageAdapter(List<Integer> imgeIds, Context context) {
        this.imgeIds = imgeIds;
        this.context = context;
    }

    @Override
    public int getCount() {
        int ret = 0;
        if (imgeIds != null) {
            ret = imgeIds.size();
        }
        return ret;
    }

    @Override
    public boolean isViewFromObject(View view, Object o) {
        return view == o;
    }

    //创建和销毁视图

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        ImageView ret = new ImageView(context);
        ret.setScaleType(ImageView.ScaleType.CENTER_CROP);
        ret.setImageResource(imgeIds.get(position));
        container.addView(ret);
        return ret;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        if (object instanceof ImageView) {
            container.removeView((ImageView) object);
        }

    }


}
